<?php

$default_config = [
    'car_status' => [
        'valid'    => 1,
        //收益期内
        'ended'    => 2,
        //收益期结束
        'punished' => 3,
        //贴条
        'protect'  => 4,
        //保护期
        'invalid'  => 5,
        //违停
    ],
    
    'index_ad'=>[
        'id'=>0,
        'title'=>'广告标题',
        'link'=>'',
        'thumb'=>'',
    ],
    
    'cfgColor'     => [
        1  => '#db1717',
        2  => '#2d3dd8',
        3  => '#dd2ad3',
        4  => '#28d6d6',
        5  => '#1fe03e',
        6  => '#cedd15',
        7  => '#e26812',
        8  => '#dee7ef',
        9  => '#000000',
        10 =>  '#4d8c4b',
    ],
    'cfgCarType'   => [
        1 => '普通车型',
        2 => '新能源车',
    ],
    
    //系统参数 - 时间 以分钟为单位
    'cfgStopLimit' => [
        //刚停车后多久可以挪车
        'stop'                  => 4,
        //同一玩家下的车位多久可以再次停车
        'stopOneParking'        => 2,
        //停车有效最长时间
        'maxStopTime'           => 8 * 60,
        //保护期时长
        'maxProtectTime'        => 60,
        //违章停车收费最长时间
        'maxDriveTime'          => 2*60,
        //违章停车每分钟扣除金币
        'DriveCredit'           => 2,
        //升级为私家车位所需金币
        'upgradeParkingPrivate' => 100000,
        //升级为充电车位所需金币
        'upgradeParkingCharge'  => 600000,
        //新能源车位收益增加比
        'ParkingFreePersent'  => 1,
        //新能源车位收益增加比
        'ParkingPrivatePersent'  => 1.1,
        //新能源车位收益增加比
        'ParkingChargePersent'  => 1.2,
        //新能源车位收益增加比
        'ParkingChargeCarPersent'  => 1.3,
        //个人拥有车数最大上限
        'CarLimit'              => 10,
        //被贴条所得百分比
        'PunishedPersent'         => 0.2,
        //贴条者所得百分比
        'PunisherPersent'         => 0.2,
        //新用户赠送金币
        'GoldForNewUser'=>10000,
        //新用户赠送车辆ID
        'CarForNewUser'=>0,
    ],
    //等级设置
    'levels'       => [
        1  => [
            'car_limit' => 1,
            'gold'      => 0,
        ],
        2  => [
            'car_limit' => 2,
            'gold'      => 0,
        ],
        3  => [
            'car_limit' => 3,
            'gold'      => 10000,
        ],
        4  => [
            'car_limit' => 4,
            'gold'      => 100000,
        ],
        5  => [
            'car_limit' => 5,
            'gold'      => 200000,
        ],
        6  => [
            'car_limit' => 6,
            'gold'      => 300000,
        ],
        7  => [
            'car_limit' => 7,
            'gold'      => 500000,
        ],
        8  => [
            'car_limit' => 8,
            'gold'      => 800000,
        ],
        9  => [
            'car_limit' => 9,
            'gold'      => 900000,
        ],
        10 => [
            'car_limit' => 10,
            'gold'      => 1000000,
        ],
    
    ],
    
    'merchant_config'=>[
        'begin_hour'=>'9',
        'end_hour'=>'22',
        'gold'=>20000,
        'day_limit'=>20,
        'lottery_rate'=>80,//中奖概率
    ],
    
    'api_config'=>[
        'host'=>'',
        'score_host'=>'',
        'social_host'=>'',
        'action_code_incre'=>'',
        'action_code_incre_sign'=>'',
        'action_code_incre_card'=>'',
        'action_code_decre'=>'',
        'demo_user_id'=>1,
        'remote_follow_switch'=>false,
    ],
    
];
//从本地文件读取配置
$config_cache_file = storage_path('app/car_config.json');

if(file_exists($config_cache_file)){
    $local_config = json_decode(file_get_contents($config_cache_file),true);
    
    if($local_config){
        if(!array_key_exists('cache',$local_config)){
            $config=[];
            //将保存的数据转换成上面的结构
            //foreach ($local_config['cfgColor'] as $color_key=>$color_value) {
            //    $config['cfgColor'][(int)substr($color_key,6,strlen($color_key))]=$color_value;
            //}
            
            for ($i=1;$i<=10;$i++){
                $config['levels'][$i]=[
                    'car_limit'=>(int)$local_config['levels']['car_limit_'.$i],
                    'gold'=>(int)$local_config['levels']['gold_'.$i],
                ];
            }
            $config['cfgStopLimit']=array_map('\intval',$local_config['cfgStopLimit']);
            
            $config['cfgStopLimit']['maxStopTime']=$local_config['cfgStopLimit']['maxStopTime']*60;
            $config['cfgStopLimit']['maxDriveTime']=$local_config['cfgStopLimit']['maxDriveTime']*60;
            $config['cfgStopLimit']['ParkingFreePersent']=$local_config['cfgStopLimit']['ParkingFreePersent']/100;
            $config['cfgStopLimit']['ParkingPrivatePersent']=$local_config['cfgStopLimit']['ParkingPrivatePersent']/100;
            $config['cfgStopLimit']['ParkingChargePersent']=$local_config['cfgStopLimit']['ParkingChargePersent']/100;
            $config['cfgStopLimit']['ParkingChargeCarPersent']=$local_config['cfgStopLimit']['ParkingChargeCarPersent']/100;
            $config['cfgStopLimit']['PunishedPersent']=$local_config['cfgStopLimit']['PunishedPersent']/100;
            $config['cfgStopLimit']['PunisherPersent']=$local_config['cfgStopLimit']['PunisherPersent']/100;
    
            //$config['index_ad'] = $local_config['index_ad'];
            //if(!starts_with($config['index_ad']['thumb'],'http')){
            //    $config['index_ad']['thumb'] = env('APP_URL').'/storage/app/public/'. $config['index_ad']['thumb'];
            //}
            $config['api_config']=$local_config['api_config'];
            $config['merchant_config']=$local_config['merchant_config'];
            $config['draw_lots_config']=$local_config['draw_lots_config'];

            //存一个缓存
            $config['cache'] = 1;
            file_put_contents($config_cache_file,json_encode($config));
        }else{
            $config = $local_config;
        }
        
        return array_merge($default_config,$config);
    }
}

return $default_config;
